//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.preferences;

import java.awt.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;

public class PreferencesGUI extends JInternalFrame {

    public PreferencesGUI() {
        jContentPane = null;
        jPanel = null;
        decimalFields = null;
        twoButton = null;
        minimumMargin = null;
        roundType = null;
        labelAndDateButton = null;
        initialize();
    }

    private void initialize() {
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/arrowRight18x18.png")));
        setTitle("Pr\351f\351rences");
        setSize(334, 206);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getJPanel(), "Center");
        }
        return jContentPane;
    }

    private JPanel getJPanel() {
        if (jPanel == null) {
            GridLayout gridLayout = new GridLayout();
            jPanel = new JPanel();
            jPanel.setLayout(gridLayout);
            gridLayout.setRows(5);
            gridLayout.setColumns(1);
            jPanel.setPreferredSize(new Dimension(328, 81));
            jPanel.add(getDecimalFields(), null);
            jPanel.add(getRoundType(), null);
            jPanel.add(getMinimumMargin(), null);
            jPanel.add(getLabelAndDateButton(), null);
            jPanel.add(getTwoButton(), null);
        }
        return jPanel;
    }

    private LabelAndComboBox getDecimalFields() {
        if (decimalFields == null) {
            decimalFields = new LabelAndComboBox();
            decimalFields.setLabel("Nombre de d\351cimal");
            decimalFields.setToolTipText("Choisir un nombre de d\351cimal apr\350s la virgule");
            decimalFields.setList(new String[]{
                        "2  (00.00)", "3  (00.000)", "4  (00.0000)", "5  (00.00000)", "6  (00.000000)"
                    });
        }
        return decimalFields;
    }

    private LabelAndComboBox getRoundType() {
        if (roundType == null) {
            roundType = new LabelAndComboBox();
            roundType.setLabel("Mode d'arrondi");
            roundType.setList(new String[]{
                        "ROUND UP", "ROUND DOWN", "ROUND CEILING", "ROUND FLOOR", "ROUND HALF UP", "ROUND HALF DOWN", "ROUND HALF EVEN", "ROUND UNNECESSARY"
                    });
        }
        return roundType;
    }

    private LabelAndTextField getMinimumMargin() {
        if (minimumMargin == null) {
            minimumMargin = new LabelAndTextField();
            minimumMargin.setVal("20.00");
            minimumMargin.setLabel("Marge accept\351e (%)");
            minimumMargin.setToolTipText("Saisir la marge minimal accept\351e sur le calcule d'un prix");
            minimumMargin.setPreferredSize(new Dimension(306, 27));
        }
        return minimumMargin;
    }

    private LabelAndDateButton getLabelAndDateButton() {
        if (labelAndDateButton == null) {
            labelAndDateButton = new LabelAndDateButton();
            labelAndDateButton.setLabelLeft("Base de donn\351es param\350tres de connexion");
            labelAndDateButton.setToolTipTextButton("Modifier les param\350tres");
            labelAndDateButton.setToolTipText("Les modifications seront active qu'apr\350s un red\351marrage de JGestcom");
            labelAndDateButton.setIconButton(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/db.png")));
        }
        return labelAndDateButton;
    }

    private TwoButton getTwoButton() {
        if (twoButton == null) {
            twoButton = new TwoButton();
            twoButton.setButtonLabelLeft("VALIDER");
            twoButton.setButtonLabelRight("ANNULER");
        }
        return twoButton;
    }

    public JButton getDBButton() {
        return getLabelAndDateButton().getButtonRight();
    }

    public JButton getOKButton() {
        return getTwoButton().getButtonLeft();
    }

    public JButton getCANCELButton() {
        return getTwoButton().getButtonRight();
    }

    public int getDecimal() {
        return getDecimalFields().getSelectedIndex() + 2;
    }

    public void setDecimal(int val) {
        getDecimalFields().setSelectedIndex(val - 2);
    }

    public void setDecimalList(String val[]) {
        getDecimalFields().setList(val);
    }

    public int getRound() {
        return getRoundType().getSelectedIndex();
    }

    public void setRound(int val) {
        getRoundType().setSelectedIndex(val);
    }

    public String getMargin() {
        return getMinimumMargin().getVal();
    }

    public void setMargin(String val) {
        getMinimumMargin().setVal(val);
    }
    private JPanel jContentPane;
    private JPanel jPanel;
    private LabelAndComboBox decimalFields;
    private TwoButton twoButton;
    private LabelAndTextField minimumMargin;
    private LabelAndComboBox roundType;
    private LabelAndDateButton labelAndDateButton;
}
